﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ClientRegister
{
    public partial class ChangeClassForStuForm : Form
    {
        public string IDStu { set; get; }
        public string IDClass { set; get; }
        public string IDSub { set; get; }

        public string IDEmp { set; get; }
        public string NameEmp { set; get; }

        SynchronizeData sync = new SynchronizeData();

        public ChangeClassForStuForm()
        {
            InitializeComponent();
        }

        private void EditClassForm_Load(object sender, EventArgs e)
        {

            ClassDataProvider cls = new ClassDataProvider();
            DataSet ds = cls.ListClassSameSubject(IDClass,IDSub);
            cobbClass.DataSource = ds.Tables[0];
            cobbClass.DisplayMember = "NameClass";
            cobbClass.ValueMember = "ID";
        }

        private void cobbClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cobbClass.SelectedValue.ToString() == "System.Data.DataRowView") return;
            else
            {
                ClassDataProvider cls = new ClassDataProvider();
                SqlDataReader sdr = cls.ClassDetail(cobbClass.SelectedValue.ToString());
                if (sdr.Read())
                {
                    txtStart.Text = DateTime.Parse(sdr.GetValue(3).ToString()).ToShortDateString();
                    txtEnd.Text = DateTime.Parse(sdr.GetValue(4).ToString()).ToShortDateString();
                    txtFee.Text = sdr.GetValue(0).ToString();
                    txtTime.Text = sdr.GetValue(2).ToString();
                    txtDayStu.Text = sdr.GetValue(1).ToString();
                }
                sdr.Close();
            }
        }

        private void btnAccept_Click(object sender, EventArgs e)
        {
            StudentInClassDataProvider changes = new StudentInClassDataProvider();
            string Note = "";
            SqlDataReader sdr = changes.selectClassForStuInfo(IDStu,IDClass);
            if(sdr.Read())
            {
                Note += sdr.GetValue(3).ToString() + "\n";
            }

            Note += "- Thay doi lop hoc ngay: " + DateTime.Now.ToString() + " Boi Nhan Vien: ID:"+IDEmp+", Ten NV: "+NameEmp+"\n";
            Note += "- Ma Lop hoc Cu: " + IDClass + "\n";

            if (changes.changeClassForStudent(IDStu, IDClass, cobbClass.SelectedValue.ToString(),Note) == 1)
            {
                MessageBox.Show("Đổi thành công");               
            }
            else{
                MessageBox.Show("Đổi không thành công");
            }

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }     
    }
}
